clear; close all; clc;

%% 1. 参数扫描设置
k_min   = -0.4; 
k_max   =  0.4;
phi_min = -2;
phi_max =  2;

Nk   = 300;          % k 方向步数
Nphi = 300;          % φ₀ 方向步数
k_values   = linspace(k_min, k_max, Nk);
phi_values = linspace(phi_min, phi_max, Nphi);

% 迭代设置
N_total = 5000;      % 总迭代次数
N_cut   = 1000;      % 去除瞬态的步数

%% 2. 调用 Rulkov 函数计算同步误差矩阵
%  (alpha, sigma, mu) = (4.5, 0.14, 0.001)
alpha1 = 4.5; 
sigma1 = 0.14; 
mu1    = 0.001;
% 对 phi_values 的扫描
[~, ~, E_a] = Rulkov(alpha1, sigma1, mu1, k_values, phi_values, N_total, 1, N_cut);

% (alpha, sigma, mu) = (6, -0.1, 0.001)
alpha2 = 6; 
sigma2 = -0.1; 
mu2    = 0.001;
[~, ~, E_b] = Rulkov(alpha2, sigma2, mu2, k_values, phi_values, N_total, 1, N_cut);

%% 3. 绘制结果
figure;

% (a) 子图：E 随 k 变化，φ₀ 作为横轴为 k, 纵轴为 φ₀
subplot(1,2,1);
imagesc(k_values, phi_values, E_a);
set(gca, 'YDir','normal');
clim([0, 1.6]);  % 固定颜色范围
colorbar; colormap jet;
xlabel('k');
ylabel('\phi_0');
title('(a) (α, σ, μ) = (4.5, 0.14, 0.001)');

% (b) 子图：E 随 k 变化
subplot(1,2,2);
imagesc(k_values, phi_values, E_b);
set(gca, 'YDir','normal');
clim([0, 1.6]);
colorbar; colormap jet;
xlabel('k');
ylabel('\phi_0');
title('(b) (α, σ, μ) = (6, -0.1, 0.001)');

